home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
9866
/
9866.xpi
/
components
/
samfind_autocomplete.js
Wrap
Text File
|
2009-09-08
|
4KB
|
186 lines
//-------------------------------------------------------------------------------------------
// Autocomplete component.
// See:
// https://developer.mozilla.org/en/How_to_implement_custom_autocomplete_search_component
//-------------------------------------------------------------------------------------------
const Ci = Components.interfaces;
const Cr = Components.results;
function samfindAutoCompleteResult(searchString,
searchResult,
defaultIndex,
errorDescription,
images,
results,
comments)
{
this._searchString = searchString;
this._searchResult = searchResult;
this._defaultIndex = defaultIndex;
this._errorDescription = errorDescription;
this._images = images;
this._results = results;
this._comments = comments;
}
samfindAutoCompleteResult.prototype =
{
_searchString : "",
_searchResult : 0,
_defaultIndex : 0,
_errorDescription : "",
_images : [],
_results : [],
_comments : [],
get searchString() {return this._searchString;},
get searchResult() {return this._searchResult;},
get defaultIndex() {return this._defaultIndex;},
get errorDescription() {return this._errorDescription;},
get matchCount() {return this._results.length;},
getImageAt : function(index)
{
return this._images[index];
},
getCommentAt : function(index)
{
return this._comments[index];
},
getValueAt : function(index)
{
return this._results[index];
},
getStyleAt : function(index)
{
return null;
},
removeValueAt : function(index, removeFromDb)
{
this._images.splice(index, 1);
this._results.splice(index, 1);
this._comments.splice(index, 1);
},
QueryInterface : function(aIID)
{
if (aIID.equals(Ci.nsIAutoCompleteResult) || aIID.equals(Ci.nsISupports))
{
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
function samfindAutoCompleteSearch()
{
this.wrappedJSObject = this;
}
samfindAutoCompleteSearch.prototype =
{
search_results : null,
startSearch : function(searchString, searchParam, result, listener)
{
var images = [];
var comments = [];
var results = [];
if (this.search_results)
{
for (var i=0; i<this.search_results.length; ++i)
{
if (this.search_results[i].indexOf(searchString) == 0)
{
images.push(null);
comments.push(null);
results.push(this.search_results[i]);
}
}
}
var newResult = new samfindAutoCompleteResult(searchString,
Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
0,
"",
images,
results,
comments);
listener.onSearchResult(this, newResult);
},
stopSearch : function()
{
},
QueryInterface : function(aIID)
{
if (aIID.equals(Ci.nsIAutoCompleteSearch) || aIID.equals(Ci.nsISupports))
{
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
var samfindAutoCompleteSearchModule =
{
ServiceCID : Components.ID("2af18a90-f5a3-11dd-87af-0800200c9a66"),
ServiceName : "samfind AutoComplete",
ServiceContractID : "@mozilla.org/autocomplete/search;1?name=samfind-autocomplete",
registerSelf : function(compMgr, fileSpec, location, type)
{
compMgr.QueryInterface(Ci.nsIComponentRegistrar).registerFactoryLocation(this.ServiceCID,
this.ServiceName,
this.ServiceContractID,
fileSpec,
location,
type);
},
unregisterSelf : function(compMgr, fileSpec, location)
{
compMgr.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactoryLocation(this.ServiceCID,
fileSpec);
},
getClassObject : function(compMgr, cid, iid)
{
if (!cid.equals(this.ServiceCID))
{
throw Cr.NS_ERROR_NO_INTERFACE;
}
if (!iid.equals(Ci.nsIFactory))
{
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
}
return this.instanceFactory;
},
canUnload : function(compMgr)
{
return true;
},
singleton : null,
instanceFactory :
{
createInstance : function(outer, aIID)
{
if (outer != null)
{
throw Cr.NS_ERROR_NO_AGGREGATION;
}
if (this.singleton == null)
{
this.singleton = new samfindAutoCompleteSearch();
}
return this.singleton.QueryInterface(aIID);
}
}
};
function NSGetModule(aCompMgr, aFileSpec)
{
return samfindAutoCompleteSearchModule;
}